package com.bianmaba.oauth2.controller.security.user;

import com.bianmaba.oauth2.bean.entity.User;
import com.bianmaba.oauth2.service.security.user.IUserService;
import com.bianmaba.spring.supports.data.beans.basc.PabeableRequest;
import com.bianmaba.spring.supports.mvc.annotations.EntityParam;
import com.bianmaba.spring.supports.mvc.annotations.JSON;
import com.bianmaba.spring.supports.mvc.annotations.MapParam;
import com.bianmaba.spring.supports.mvc.controller.CrudController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;
import java.util.LinkedHashMap;

@RestController
@RequestMapping(value = "management/security/user")
public class MGTUserController extends CrudController<User, String> {
    @Autowired
    private IUserService service;

    @Override
    protected IUserService getService() {
        return service;
    }


    @JSON()
    @RequestMapping(value = "/save")
    public User save(@EntityParam User entity) {
        User result = getService().save(entity);
        return result;
    }


    @JSON()
    @RequestMapping(value = "/query")
    public Page<User> query(@MapParam LinkedHashMap<String, Object> params, @EntityParam PabeableRequest pageable) {
        return getService().query(params, pageable);
    }

}
